package com.imaker.action;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.imaker.domain.ActionInfo;
import com.imaker.domain.UserInfo;
import com.imaker.service.ActionService;
import com.imaker.utils.CacheUtils;
import com.imaker.vo.CacheInfo;
import com.opensymphony.xwork2.ActionContext;

/**
 * 工作空间Action
 * @author mayonghua
 *
 */
@Controller
@Scope("prototype")
public class WorkSpaceAction extends BaseAction {

	@Autowired
	private ActionService actionService = null;
	private List<ActionInfo> actionList;
	
	/**
	 * 产生左边的类别
	 * @return
	 */
	public String tree() throws Exception{
		actionList = actionService.findAll();
		actionList = filter(actionList);
		return SUCCESS;
	}
	
	/**
	 * 过滤action权限
	 * @param actionList
	 * @return
	 */
	public List<ActionInfo> filter(List<ActionInfo> actionList){
		//获得用户信息
		UserInfo user = (UserInfo)ActionContext.getContext().getSession().get("user");
		if(user==null){
			return null;
		}
		CacheInfo ci = (CacheInfo)CacheUtils.get("ROLEOPERATE",user.getId());
		List filterList = new ArrayList();
		for(ActionInfo actionInfo:actionList){
			String webId = actionInfo.getWebId();
			String flag = ci.getOperate().get(webId);
			if("T".equals(flag)){
				filterList.add(actionInfo);
			}
		}
		return filterList;
	}

	public ActionService getActionService() {
		return actionService;
	}

	public void setActionService(ActionService actionService) {
		this.actionService = actionService;
	}

	public List<ActionInfo> getActionList() {
		return actionList;
	}

	public void setActionList(List<ActionInfo> actionList) {
		this.actionList = actionList;
	}
	
}
